import os
import json
import re
hover = {}
paramhover = {}
with open("snippets.json","r",encoding="utf8") as f:
    content = f.read()
    j = json.loads(content)
    # print(j)
    for key in j:
        item = j.get(key)
        hover[item['prefix']] = {
            "example": key
        }
        body = item['body']
        print(body)
        pattern = r"\$\{\d+:(.+?)\}"
        matches = re.findall(pattern, body[0])
        if len(matches) == 0:
            pattern = r"(\w+)=\$\{\d+\}"
            matches = re.findall(pattern, body[0])
        result = {i + 1: matches[i] for i in range(len(matches))}
        result["paramall"] = " ".join(matches)
        paramhover[item['prefix']] = result
    with open("hover.json","w",encoding="utf8") as f1:
        f1.write(json.dumps(hover,indent=4,ensure_ascii=False))
    with open("paramhover.json","w",encoding="utf8") as f1:
        f1.write(json.dumps(paramhover,indent=4,ensure_ascii=False))